
package com.supcon.exchangedata.job;

import com.supcon.exchangedata.service.*;
import com.supcon.exchangedata.service.gj.*;
import com.supcon.exchangedata.service.hj.*;
import com.supcon.exchangedata.service.lq.LqBasicService;
import com.supcon.exchangedata.service.lq.LqCarGpsService;
import com.supcon.exchangedata.service.lq.LqCarService;
import com.supcon.exchangedata.service.lq.LqOperationService;
import com.supcon.exchangedata.service.rq.GasLiquidInfoService;
import com.supcon.exchangedata.service.rq.GasNaturalInfoService;
import com.supcon.exchangedata.service.sw.SwBasicService;
import com.supcon.exchangedata.service.sw.SwOperationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.LinkedHashMap;

/**
 * Created with IntelliJ IDEA.
 * 基础数据定时任务设计
 *
 * @Author: yangbin
 * @Date: 2022/03/16/13:55
 * @Description:
 */


@Component
@EnableScheduling
@Lazy(value = false)
@Slf4j
public class BaseDataJob {

    @Resource
    private SwOperationService swOperationService;
    @Resource
    private HjOperationService hjOperationService;

    @Resource
    private DayGasSyncService dayGasSyncService;

    @Resource
    private DayAndMonthSyncService dayAndMonthSyncService;

    @Resource
    private GarbageStationService garbageStationService;
    @Resource
    private SwBasicService swBasicService;
    @Resource
    private GarbageDisposalSiteService garbageDisposalSiteService;
    @Resource
    private GarbageRouteService garbageRouteService;
    @Resource
    private GarbagePointService garbagePointService;
    @Resource
    private GarbageCarService garbageCarService;
    @Resource
    private GarbageCarGpsService garbageCarGpsService;
    @Resource
    private GjOperationService gjOperationService;
    @Resource
    private GjBasicService gjBasicService;
    @Resource
    private BusCarGpsService busCarGpsService;
    @Resource
    private BusTranService busTranService;
    @Resource
    private BusOtherDataService busOtherDataService;
    @Resource
    private LqBasicService lqBasicService;
    @Resource
    private LqCarGpsService lqCarGpsService;
    @Resource
    private LqCarService lqCarService;
    @Resource
    private CommonMethodService commonMethodService;
    @Resource
    private GarbageTransferStationService garbageTransferStationService;
    @Resource
    private LqOperationService lqOperationService;
    @Resource
    private GasLiquidInfoService gasLiquidInfoService;
    @Resource
    private GasNaturalInfoService gasNaturalInfoService;
    @Resource
    private HjCleanOrganizedService hjCleanOrganizedService;
    @Resource
    private SgjjtBikeTradeService sgjjtBikeTradeService;
    @Async
    @Scheduled(cron = "* 0/5 * * * ?")
    public void cleanGps() {
        try {
            commonMethodService.saveCurrentValue();
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }

    }

    @Async
    @Scheduled(cron = "* 3/30 * * * ?")

// 环境相关数据最新 ，1小时请求一次  每小时52分请求一次
    public void garbageOperationJob() {
        try {
            this.hjOperationService.hjBurnOperationData();
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }
        try {
            this.hjOperationService.hjGarbageHandleData();
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }

        try {
            this.hjOperationService.HjGarbageCleanData();
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }
        try {
            this.hjOperationService.HjGarbageTranData();
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }
        try {
            this.hjOperationService.HjSewageTreatment();
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }
        try {
            this.hjOperationService.garbageElectricityInfo();
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }
        try {
            this.lqOperationService.LqDayOperationData();
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }

    }


    @Async
    @Scheduled(cron = "0 0 4 1/1 * ?")
    public void garbageOperationYearJob() {
        LocalDateTime endTime = LocalDate.now().atStartOfDay();
        LocalDateTime startTime = endTime.minusYears(1);
        try {
            this.hjOperationService.hjBurnOperationByYearData(startTime, endTime);
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }
        try {
            this.hjOperationService.hjGarbageHandleAllData(startTime, endTime);
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }

        try {
            this.hjOperationService.hjGarbageCleanByYearData(startTime, endTime);
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }
        try {
            this.hjOperationService.HjGarbageTranDataByYearData(startTime, endTime);
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }
        try {
            this.hjOperationService.HjSewageTreatmentByYearData(startTime, endTime);
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }
        try {
            this.hjOperationService.garbageElectricityInfoByYearData(startTime, endTime);
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }

    }


    @Async
    @Scheduled(cron = "0 1 0/2 * * ? ")
    public void garbageOperationMonthJob() {
        LocalDateTime endTime = LocalDate.now().atStartOfDay();
        LocalDateTime startTime = endTime.minusMonths(2);
        try {
            this.hjOperationService.hjBurnOperationByYearData(startTime, endTime);
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }
        try {
            this.hjOperationService.hjGarbageHandleAllData(startTime, endTime);
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }

        try {
            this.hjOperationService.hjGarbageCleanByYearData(startTime, endTime);
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }

        try {
            this.hjOperationService.HjGarbageTranDataByYearData(startTime, endTime);
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }
        try {
            this.hjOperationService.HjSewageTreatmentByYearData(startTime, endTime);
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }
        try {
            this.hjOperationService.garbageElectricityInfoByYearData(startTime, endTime);
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }
        try {
            this.lqOperationService.LqDayOperationDataByYear(startTime, endTime);
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }

    }

    @Async
    @Scheduled(cron = "* 3/30 * * * ?")
//  水务相关  1小时请求一次  每小时52分请求一次
    public void waterOperationJob() {
        try {
            swOperationService.dayOperationData();
        } catch (Exception e) {
            log.info("水务日运营数据错误信息:{}", e.getMessage());
        }

        try {
            swOperationService.dayWaterOperationData();
        } catch (Exception e) {
            log.info("供水错误信息:{}", e.getMessage());
        }

        try {
            swOperationService.daySewageOperationData();
        } catch (Exception e) {
            log.info("污水错误信息:{}", e.getMessage());
        }
    }


    @Async
    @Scheduled(cron = "0 0 4 1/1 * ?")
    public void waterOperationYearJob() {
        LocalDateTime endTime = LocalDate.now().atStartOfDay();
        LocalDateTime startTime = endTime.minusYears(1);
        try {
            swOperationService.dayOperationByYear(startTime, endTime);
        } catch (Exception e) {
            log.info("水务日运营数据（年）错误信息:{}", e.getMessage());
        }

        try {
            swOperationService.dayWaterByYearData(startTime, endTime);
        } catch (Exception e) {
            log.info("供水（年）错误信息:{}", e.getMessage());
        }

        try {
            swOperationService.daySewageOperationByYearData(startTime, endTime);
        } catch (Exception e) {
            log.info("污水（年）错误信息:{}", e.getMessage());
        }
    }

    @Async
    @Scheduled(cron = "0 1 0/2 * * ? ")
    public void waterOperationMonthJob() {
        LocalDateTime endTime = LocalDate.now().atStartOfDay();
        LocalDateTime startTime = endTime.minusMonths(2);
        try {
            swOperationService.dayOperationByYear(startTime, endTime);
        } catch (Exception e) {
            log.info("水务日运营数据（月）错误信息:{}", e.getMessage());
        }

        try {
            swOperationService.dayWaterByYearData(startTime, endTime);
        } catch (Exception e) {
            log.info("供水（月）错误信息:{}", e.getMessage());
        }

        try {
            swOperationService.daySewageOperationByYearData(startTime, endTime);
        } catch (Exception e) {
            log.info("污水（月）错误信息:{}", e.getMessage());
        }
    }


    @Async
    @Scheduled(cron = "0 30 * * * ?")
    public void syncGasDataNew() {
        this.dayGasSyncService.syncNewList();
    }

    @Async
    @Scheduled(cron = "0 30 0/2 * * ? ")
    public void syncDayData() {
        dayAndMonthSyncService.SyncCurrentDayData(30);
        // LinkedHashMap<Long,Long> indexMap = new LinkedHashMap<>();
        //沥青
    }

    @Async
    @Scheduled(cron = "55 55 23 * * ? ")
    public void syncMonthData() {
        LocalDate now = LocalDate.now();
        int dayOfMonth = now.getDayOfMonth();
        if (dayOfMonth > 2) {
            dayAndMonthSyncService.SyncMonthData(1);
        }
        dayAndMonthSyncService.SyncMonthData(0);
    }


    @Async
    @Scheduled(cron = "0 58/1 * * * ? ")
    public void synchronizationOrganized() {
        try {
            hjCleanOrganizedService.synchronizationOrganized();
        } catch (Exception e) {
            log.info("环境数据 Organized 错误信息:{}", e.getMessage());
        }
        try {
            this.hjOperationService.hjCleanRecycleNew();
        } catch (Exception e) {
            log.info("错误信息 hjCleanRecycleNew :{}", e.getMessage());
        }

    }


    @Async
    @Scheduled(cron = "0 0 7 * * ?")
    public void newGjBikeTradeList(){
        try {
            sgjjtBikeTradeService.acquireBike();
        }catch (Exception e){
            log.info("公交 newGjBikeTradeList 错误信息:{}", e.getMessage());
        }

    }
    @Async
    @Scheduled(cron = "0 0/5 * * * ? ")
    public void waitCarTimeNew(){
        try {
            hjOperationService.waitCarTimeNew();
        } catch (Exception e) {
            log.info("环境数据 waitCar 错误信息:{}", e.getMessage());
        }
    }

    @Async
    @Scheduled(cron = "0 0 1 1/1 * ?")
    public void baseD() {

        try {
            swBasicService.swBasicInfo();
        } catch (Exception e) {
            log.info("水务基础数据错误信息:{}", e.getMessage());
        }

        try {
            //减量综合体
            garbageStationService.transGarbageStation();
        } catch (Exception e) {
            log.info("减量综合体错误信息:{}", e.getMessage());
        }

        try {
            //垃圾处置场信息
            garbageDisposalSiteService.transGarbageDisposalSite();
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }
        try {
            //清运线路
            garbageRouteService.transGarbageRouteNew();
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }
        //垃圾中转站
        try {
            garbageTransferStationService.transGarbageTransferStation();
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }
        //
        try {
            lqBasicService.updateLqBasicInfoNew();
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }
//
        try {
            lqBasicService.updateLqBasicInfo1New();
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }
    }

    @Async
    @Scheduled(cron = "0 0 2 1/1 * ?")
    public void baseE() {
        try {
            //环境垃圾清运点
            garbagePointService.tranGarbagePointDataNew();
        } catch (Exception e) {
            log.info("环境垃圾清运点错误信息:{}", e.getMessage());
        }
    }


    //公交运营运营数据    @Scheduled(cron = "* 0/3 * * * ?")
    @Async
    @Scheduled(cron = "* 0/3 * * * ?")
    public void operation() {
        //自行车出租还量
        try {
            gjOperationService.gjBikeOperation();
        } catch (Exception e) {
            log.info("自行车出租还量错误信息:{}", e.getMessage());
        }

        try {
            // 按支付方式客流量
            gjOperationService.passerByPayType();
        } catch (Exception e) {
            log.info("按支付方式客流量错误信息:{}", e.getMessage());
        }
        try {
            //运营实时指标
            gjOperationService.busOperation();
            LocalDateTime startTime = LocalDate.now().atStartOfDay();
            LocalDateTime endTime = LocalDateTime.now();
            gjOperationService.busOperationByTime(startTime, endTime);
        } catch (Exception e) {
            log.info("运营实时指标错误信息:{}", e.getMessage());
        }

        try {
            //日运营信息
            gjOperationService.gjDailyOperation();
        } catch (Exception e) {
            log.info("日运营信息错误信息:{}", e.getMessage());
        }

    }

    //公交运营数据一个月  @Async
    //    @Scheduled(cron = "0 1 0/2 * * ? ")
    @Async
    @Scheduled(cron = "0 1 0/2 * * ? ")
    public void operationMonth() {
        LocalDateTime endTime = LocalDate.now().atStartOfDay().minusDays(1);
        LocalDateTime startTime = endTime.minusMonths(1);
        //自行车出租还量
        try {
            gjOperationService.gjBikeOperationByYear(startTime, endTime);
        } catch (Exception e) {
            log.info("自行车出租还量（月）错误信息:{}", e.getMessage());
        }

        try {
            // 按支付方式客流量
            gjOperationService.passerByPayTypeByYear(startTime, endTime);
        } catch (Exception e) {
            log.info("按支付方式客流量（月）错误信息:{}", e.getMessage());
        }
        try {
            //日运营信息
            gjOperationService.gjDailyOperationByYear(startTime, endTime);
        } catch (Exception e) {
            log.info("日运营信息（月）错误信息:{}", e.getMessage());
        }

    }

    //公交运营数据一年  @Scheduled(cron = "0 0 4 1/1 * ?")
    @Async
    @Scheduled(cron = "0 0 4 1/1 * ?")
    public void operationYear() {
        LocalDateTime endTime = LocalDate.now().atStartOfDay().minusDays(1);
        LocalDateTime startTime = endTime.minusYears(1);
        //自行车出租还量
        try {
            gjOperationService.gjBikeOperationByYear(startTime, endTime);
        } catch (Exception e) {
            log.info("自行车出租还量（年）错误信息:{}", e.getMessage());
        }

        try {
            // 按支付方式客流量
            gjOperationService.passerByPayTypeByYear(startTime, endTime);
        } catch (Exception e) {
            log.info("按支付方式客流量（年）错误信息:{}", e.getMessage());
        }
        try {
            //日运营信息
            gjOperationService.gjDailyOperationByYear(startTime, endTime);
        } catch (Exception e) {
            log.info("日运营（年）错误信息:{}", e.getMessage());
        }

    }

    //公交基础数据
    @Async
    @Scheduled(cron = "0 0 1 1/1 * ?")
    public void operationBaSic() {


        //车辆信息
        try {
            busTranService.transData();
        } catch (Exception e) {
            log.info("车辆错误信息:{}", e.getMessage());
        }

        try {
            //电子站牌信息
            gjBasicService.busElectricStop();
        } catch (Exception e) {
            log.info("电子站牌错误信息:{}", e.getMessage());
        }
        try {
            //场站信息
            gjBasicService.busStopStation();
        } catch (Exception e) {
            log.info("场站错误信息:{}", e.getMessage());
        }
        try {
            //公交站点信息
            gjBasicService.busStation();
        } catch (Exception e) {
            log.info("公交站点错误信息:{}", e.getMessage());
        }

        try {
            //路桥养护基地
            lqBasicService.updateLqBasic();
        } catch (Exception e) {
            log.info("路桥养护基地错误信息:{}", e.getMessage());
        }



    }

    @Async
    @Scheduled(cron = "0 52 * * * ?")
    public void operationBaSic1() {
        //自行车站点信息
        try {
            gjBasicService.updateBikeStation();
        } catch (Exception e) {
            log.info("自行车站点错误信息:{}", e.getMessage());
        }
        // 线路信息
        try {
            gjBasicService.busRouteInfoStation();
        } catch (Exception e) {
            log.info("线路信息错误信息:{}", e.getMessage());
        }
        try {
            //线路分布信息
            gjBasicService.busRouteInfo();
        } catch (Exception e) {
            log.info("线路分布信息错误信息:{}", e.getMessage());
        }
        try {
            //错误信息
            busOtherDataService.BusPbjhData();
        } catch (Exception e) {
            log.info("错误信息错误信息:{}", e.getMessage());
        }



    }
    //同步数据到水务前置库
    @Async
    @Scheduled(cron = "0 0 11 * * ?")
    public void gsUser() {
        try {
            swBasicService.gsUser();
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }
    }



    //推送到第燃气前置库
    @Async
    @Scheduled(cron = "0 0 1 1/1 * ?")
    public void rqPush() {
        try {
        gasLiquidInfoService.newLiqIdInfo();
        }catch (Exception e) {
            log.info("gasLiquidInfoService 错误信息:{}", e.getMessage());
        }
        try {
            gasNaturalInfoService.newNaturalInfo();
        }catch (Exception e) {
            log.info("gasNaturalInfoService 错误信息:{}", e.getMessage());
        }
        try {
            dayGasSyncService.rqNewInfoUser();
        } catch (Exception e) {
            log.info("dayGasSyncService User:{}", e.getMessage());
        }
    }

    public void rqUser(){


    }


      @Async
      @Scheduled(cron = "0 0 10 * * ?")
      public void rqInfoByType1() {
          try {
              dayGasSyncService.rqInfo("1");
          } catch (Exception e) {
              log.info("错误信息:{}", e.getMessage());
          }
      }


    @Async
    @Scheduled(cron = "0 0 10 * * ?")
    public void rqInfoByType2() {
        try {
            dayGasSyncService.rqInfo("1");
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }
    }

    @Async
    @Scheduled(cron = "0 0 10 * * ?")
    public void rqInfoByType3() {
        try {
            dayGasSyncService.rqInfo("3");
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }
    }

    //-----------车辆打包时打开
/*    @Async
    @Scheduled(cron = "0 0/3 * * * ?")
    public void busGps() {
        try {
            log.info("同步公交车实时数据:--------->正在执行中-----------");
            busCarGpsService.syncBusCarGps();
            log.info("同步公交车实时数据:--------->已完成!--------------");
        } catch (Exception e) {
            log.info("公交1009错误信息错误信息:{}", e.getMessage());
        }

    }*/

/*    @Async
    @Scheduled(cron = "0 0/4 * * * ?")
    public void busGpsHis() {
        try {
            log.info("同步公交车历史数据:--------->正在执行中-----------");
            busCarGpsService.newSyncBusCarGps();
            log.info("同步公交车历史数据:--------->已完成!--------------");
        } catch (Exception e) {
            log.info("公交历史数据1009错误信息错误信息:{}", e.getMessage());
        }
    }*/

/*    @Async
    @Scheduled(cron = "0 0 1 1/1 * ?")
    public void  hjGps(){
        try {
            //车辆同步环境
            garbageCarService.tranGarbageCar();
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }
    }

    @Async
    @Scheduled(cron = "0 0 1 1/1 * ?")
    public void rqCar() {
        try {
            //路桥车辆信息
            lqCarService.tranRoadCar();
        } catch (Exception e) {
            log.info("路桥车辆错误信息:{}", e.getMessage());
        }
    }

    @Async
    @Scheduled(cron = "* 0/10 * * * ?")
    public void LqGps() {
        try {
            lqCarGpsService.syncLqCarGps();
        } catch (Exception e) {

        }
    }

    @Async
    @Scheduled(cron = "* 0/10 * * * ?")
    public void cleanGps1() {
        try {
            garbageCarGpsService.syncCleanCarGps();
        } catch (Exception e) {
            log.info("错误信息:{}", e.getMessage());
        }

    }


    @Async
    @Scheduled(cron = "0 0 0 * * ?")
    public void deleteByHis(){
        try {
            log.info("删除数据------------------------进行中-----");
            commonMethodService.deleteByHis();
            log.info("删除数据------------------------已完成-----");
        } catch (Exception e) {
            log.info("删除信息错误", e.getMessage());
        }
    }

    // 1009车辆轨迹

        @Async
    @Scheduled(cron = "0 0/4 * * * ? ")
    public void newSyncBusCarGps(){
        log.info("1009车辆轨迹同步历史数据开始------------------------进行中-----");
        busCarGpsService.gjHis();
        log.info("1009车辆轨迹同步历史数据结束------------------------已完成!-----");
    }

   // 4012车辆轨迹
    @Async
    @Scheduled(cron = "0 0/5 * * * ? ")
    public void newSyncCleanCarGps(){
        log.info("4012车辆轨迹同步数据开始------------------------进行中-----");
        garbageCarGpsService.newSyncCleanCarGps();
        log.info("4012车辆轨迹同步数据结束------------------------已完成!-----");
    }*/
}
